package com.erci.controller.admin;

import com.erci.entity.DTO.AnimeDTO;
import com.erci.result.PageResult;
import com.erci.result.Result;
import com.erci.service.AnimeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin(origins = "http://localhost:5173")
@RestController
@RequestMapping("/admin/api/anime")
@Slf4j
public class AnimeController {
    @Autowired
    private AnimeService animeService;

    // 分页查询
    @GetMapping("/list")
    public Result<PageResult> queryList(Integer page, Integer pageSize, String name,
                                        @RequestParam(required = false) List<Integer> categoryIds, String status) {
        PageResult pageResult = animeService.queryList(page,pageSize, name,categoryIds,status);
        return Result.success(pageResult);
    }

    // 新增
    @PostMapping("/add")
    public Result<String> add(@RequestBody AnimeDTO animeDTO) {
        animeService.add(animeDTO);
        return Result.success("添加成功");
    }

    //删除
    @PostMapping("/delete")
    public Result<String> delete(@RequestBody AnimeDTO animeDTO) {
        log.info("删除");
        animeService.delete(animeDTO);
        return Result.success("删除成功");
    }
    //修改
    @PostMapping("/update")
    public Result<String> update(@RequestBody AnimeDTO animeDTO) {
        animeService.update(animeDTO);
        return Result.success("修改成功");
    }
}
